//
//  DYZInsideColourController.m
//  汽车项目实战
//
//  Created by 白白龙腾 on 16/8/19.
//  Copyright © 2016年 heima. All rights reserved.
//

#import "DYZInsideColourController.h"
#import "DYZLaunchCarsController.h"
#import "DYZCustominsideColourController.h"
static NSString *cellid = @"cellid";
@interface DYZInsideColourController ()
@property (nonatomic , strong)NSArray *colourArray;
@end

@implementation DYZInsideColourController

- (void)viewDidLoad {
    [super viewDidLoad];
    //禁用弹性效果
    self.tableView.bounces = NO;
    //隐藏没有内容的cell的下划线
    self.tableView.tableFooterView = [[UIView alloc]init];
    UIButton *aButton = [[UIButton alloc]init];
    [aButton setImage:[UIImage imageNamed:@"btn_backItem"] forState:UIControlStateNormal];
    [aButton sizeToFit];
    //添加点击事件
    [aButton addTarget:self action:@selector(aButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithCustomView:aButton];
    self.navigationItem.leftBarButtonItem = item;
    //设置navitem的文字
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
    [customLab setTextColor:[UIColor blackColor]];
    [customLab setText:@"选择内饰颜色"];
    customLab.font = [UIFont boldSystemFontOfSize:20];
    self.navigationItem.titleView = customLab;
    //注册单元格
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellid];
    
    //初始化颜色数组
    self.colourArray = @[@"不限",@"米",@"棕",@"黑",@"红",@"灰",@"蓝",@"",@"自定义内饰颜色"];
}

//点击aButton时pop回上一个界面
- (void)aButtonClick{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.colourArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid forIndexPath:indexPath];
    if (indexPath.row < 7) {
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    if (indexPath.row == 7) {
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.userInteractionEnabled = NO;
    }
    if (indexPath.row == 8) {
        //设置选中颜色也是这个颜色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.contentView.backgroundColor = [UIColor blueColor];
        cell.textLabel.backgroundColor = [UIColor blueColor];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.text = self.colourArray[indexPath.row];
        cell.tintColor = [UIColor whiteColor];
        return cell;
    }
    cell.textLabel.text = self.colourArray[indexPath.row];
    
    return cell;
}

//设置不同行的cell的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 7) {
        return 231;
    }else if (indexPath.row == 8){
        return 64;
    }
    return 44;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消点击效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row == 8) {
        DYZCustominsideColourController *cac = [[DYZCustominsideColourController alloc]init];
        [self.navigationController pushViewController:cac animated:YES];
        return;
    }
    
    //返回发布车源界面
    [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
    
}


@end
